//
//  CTPGeocodeFetcher.m
//  citipad
//
//  Created by Chih Yuan Liu on 3/8/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CTPGeocodeFetcher.h"
#import "JSON.h"

@implementation CTPGeocodeFetcher


- (void)requestSucceeded {
	NSString *responseString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];
	NSDictionary *dictionary = [responseString JSONValue];
	NSDictionary *jdata = [dictionary objectForKey:@"data"];
	NSString* lat = (NSString*)[jdata objectForKey:@"lat"];
	NSString* lng = (NSString*)[jdata objectForKey:@"lng"];
	[delegate geocodeFetcherSucceeded:self lat:[lat floatValue] lng:[lng floatValue]];
	[delegate geocodeFetcherEnd:self];
}

-(void)requestFailed:(NSError*)error {
	[delegate geocodeFetcherFailed:self];
	[delegate geocodeFetcherEnd:self];
}

-(NSString*) URLForCtpProxy:(NSString*) tags{
	NSString* url = [NSString stringWithFormat:
					 @"http://114.34.48.246/CtpSvr/svr.ashx?method=geocode&key=%@", 
					 tags];
	return url;
}

-(void)geocode:(NSString*) tags{
	NSString* url = [self URLForCtpProxy:tags];
	NSLog(@"%@", url);
	[super requestGET:url];
	[delegate geocodeFetcherBegin:self];
}


@synthesize delegate;

@end
